package com.ellwood.IPGuard.infrastruction.repository.system.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ellwood.IPGuard.common.core.basic.EntityRepositoryImpl;
import com.ellwood.IPGuard.infrastruction.domain.entity.system.UmsSysUserEntity;
import com.ellwood.IPGuard.infrastruction.mapper.system.UmsSysUserMapper;
import com.ellwood.IPGuard.infrastruction.repository.system.UmsSysUserRepository;
import org.apache.ibatis.executor.BatchResult;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @ProjectName: IPGuard-boot
 * @PackageName: com.ellwood.IPGuard.infrastruction.repository.system.impl
 * @ClassName: UmsSysUserRepositoryImpl
 * @Description: // 用户实体仓库接口实现
 * @Author: Ellwood
 * @CreateDate: 2024/9/25 - 下午4:55
 * @Version: V1.0.0
 */

@Component
public class UmsSysUserRepositoryImpl extends EntityRepositoryImpl<UmsSysUserEntity> implements UmsSysUserRepository {
        
        private final UmsSysUserMapper userMapper;
        
        /**
         * 构造函数
         * ---> 注入Mapper，不能使用Lombok的@RequiredArgsConstructor注解，否则会报错
         */
        public UmsSysUserRepositoryImpl(UmsSysUserMapper userMapper) {
                super(userMapper);
                this.userMapper = userMapper;
        }
        
        @Override
        public List<UmsSysUserEntity> getUserList(Map<String, Object> pageParams) {
                return userMapper.getUserList(pageParams);
        }
        
        @Override
        public UmsSysUserEntity getUserByUsername(String username) {
                return userMapper.getByUsername(username);
        }
        
        @Override
        public UmsSysUserEntity getUserByMobile(String mobile) {
                return userMapper.getByMobile(mobile);
        }
        
        @Override
        public int insert(UmsSysUserEntity userEntity) {
                return userMapper.insert(userEntity);
        }
        
        @Override
        public int updateUser(UmsSysUserEntity userEntity) {
                return userMapper.updateById(userEntity);
        }
        
        @Override
        public int userRemove(List<Long> idList) {
                return userMapper.deleteByIds(idList);
        }
        
        @Override
        public int userLogicRemove(Long userId) {
                return userMapper.userLogicRemove(userId);
        }
        
        @Override
        public void insertBatch(List<UmsSysUserEntity> userList) {
                for (UmsSysUserEntity user : userList) {
                        userMapper.insert(user);
                }
                
        }
        
        @Override
        public List<UmsSysUserEntity> getExportUserList() {
                List<UmsSysUserEntity> entities = userMapper.selectList(Wrappers.lambdaQuery(UmsSysUserEntity.class).eq(UmsSysUserEntity::getDeleted, 0));
                return entities;
        }
}
